/**
 * @file node.h
 * Header containing the "global" variables of a node instance.
 * This way, we can eventually create multiple instances of a node.
 */

#ifndef _NODE_H
#define _NODE_H

#include "addr.h"
#include "search.h"

static const int NODE_BACKLOG = 8; // queue size for listen()

/**
 * @struct The structure containing all the parameters of a P2P node
 * @see _Node
 */
typedef struct _Node Node;

void node_init(Node *node, const Addr *join);
void node_loop(Node *node);
void node_shutdown(Node *node, int status);

struct _Node {
	char *srv_name; ///< server name
	char *dir_name; ///< the working directory of the server
	Addr *addr; ///< P2P address of this node
	Addr *addr_left; ///< P2P address of the left neighbour
	Addr *addr_right; ///< P2P address of the right neighbour
	int port_ui; ///< listening port for the UI
	int sock_ui_listen; ///< UI listening socket
	int sock_ui_conn; ///< UI connection socket
	int sock_tcp_listen; ///< TCP listening socket
	int sock_tcp_conn; ///< TCP connection socket
	int sock_udp; ///< UDP listening socket
	int verbosity; ///< controls the amount of information which is reported
	uint32_t req_id; ///< ID of the last search
	Search *search; ///< last search
};

#endif /* _NODE_H */
